﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Iacym.Entities;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Iacym.Repository.Mapping
{
    public class USUARIOMap : EntityTypeConfiguration<USUARIO>
    {
        public USUARIOMap()
        {
            this.Property(t => t.Numero)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            // Primary Key
            this.HasKey(t => t.PersonaId);

            // Properties
            this.Property(t => t.PersonaId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.Password)
                .IsRequired();

            // Table & Column Mappings
            this.ToTable("USUARIO");
            this.Property(t => t.Numero).HasColumnName("Numero");
            this.Property(t => t.PersonaId).HasColumnName("PersonaId");
            this.Property(t => t.RolId).HasColumnName("RolId");       
            this.Property(t => t.Password).HasColumnName("Password");

            // Relationships
            this.HasRequired(t => t.PERSONA)
                .WithOptional(t => t.USUARIO);
            this.HasRequired(t => t.ROL)
                .WithMany(t => t.USUARIOs)
                .HasForeignKey(d => d.RolId);

        }
    }
}
